﻿using System.Threading.Tasks;
using System.Threading;
using System;
using System.Windows;
using System.Windows.Controls;

using GeneralTool.CoreLibrary.Models;
using GeneralTool.CoreLibrary.TaskLib;

namespace TaskHostLib
{
    /// <summary>
    /// TaskManagerView.xaml 的交互逻辑
    /// </summary>
    public partial class TaskManagerView : UserControl
    {
        private TaskManager manager;

        public TaskManagerView()
        {
            InitializeComponent();
        }

        public DoTaskParameterItem SelectedTaskInfo
        {
            get
            {
                var model = this.TaskTab.SelectedItem as TaskModel;

                var taskinfo = model.SelectedItem?.DoTaskParameterItem;
                return taskinfo;
            }
        }

   
        public void Init(params BaseTaskInvoke[] baseTaskInvokes)
        {
            this.manager = new TaskManager();
            manager.OpenWithoutServer(baseTaskInvokes);
            manager.GetInterfaces();
            var models = manager.TaskModels;
            this.TaskTab.ItemsSource = models;
        }


        private void InterfaceList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        public event EventHandler<TaskManager> RunMethodEvent;
        private void RunMethod(object sender, RoutedEventArgs e)
        {
            this.RunMethodEvent?.Invoke(this, this.manager);
        }
    }
}
